import { _decorator, Component, director, Label, Node, ScrollView } from 'cc';
import { BasicUI } from '../../Init/Basic/BasicUI';
import { SDKEventDef } from '../../Init/Managers/TaskSDK/SDKEventDef';
import { WebDataProxy } from '../../Init/Managers/TaskSDK/数据代理类/WebDataProxy';
import { TaskCell } from './TaskCell';
import { UISystem } from '../../Init/SystemUI/UISystem';
import { UIEnum } from '../../Init/SystemUI/UIEnum';
const { ccclass, property } = _decorator;

@ccclass('TaskUI')
export class TaskUI extends BasicUI {
    @property(ScrollView)
    ScrollView: ScrollView = null;
    protected onEvents(): void {
        director.on(SDKEventDef.UPDATE_TSAK_INFO, this.updateTaskList, this)
    }
    onLoad() {
        this.updateTaskList();
    }
    public offEvents(): void {
        director.off(SDKEventDef.UPDATE_TSAK_INFO, this.updateTaskList, this)
    }

    private updateTaskList() {
        let list = WebDataProxy.inst.TaskList;
        for (let i = 0; i < list.length; i++) {
            let item = this.ScrollView.content.children[i];
            if (item == null) {
                continue;
            }
            let nodes = item.getComponent<TaskCell>(TaskCell);
            if (nodes == null) {
                continue;
            }
            nodes.SetUI(i, list[i]);
        }
    }

    private onBindPhoneClick() {
        UISystem.showUI(UIEnum.TaskBindPhoneUI);
    }

    private closeBtnClick() {
        UISystem.hideUI(UIEnum.TaskUI);
    }
}

